Skip to content

KeyCombinationEdit

Base classes

Name Children Inherits
WidgetMixin
prettyqt.widgets.widget
QKeySequenceEdit
PySide6.QtWidgets
QKeySequenceEdit(self, /, parent: PySide6.QtWidgets.QWidget | None \= None, *, keySequence: PySide6.QtGui.QKeySequence | None \= None, clearButtonEnabled: bool | None \= None, maximumSequenceLength: int | None \= None, finishingKeyCombinations: collections.abc.Sequence[PySide6.QtCore.QKeyCombination] | None \= None) -> None

⋔ Inheritance diagram

graph TD
  3444579690["custom_widgets.KeyCombinationEdit"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  1682701161["QtWidgets.QKeySequenceEdit"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  829357528 --> 3444579690
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  1682701161 --> 3444579690
  3620195106 --> 1682701161
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: WidgetMixin, QKeySequenceEdit

Source code in prettyqt/custom_widgets/editors/keycombinationedit.py
class KeyCombinationEdit(widgets.WidgetMixin, widgets.QKeySequenceEdit):
    value_changed = core.Signal(core.QKeyCombination)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setMaximumSequenceLength(1)

    def __repr__(self):
        return get_repr(self, self.get_value())

    def _on_value_change(self, val):
        self.value_changed.emit(val[0])

    def set_value(self, value: datatypes.KeyCombinationType):
        seq = value if isinstance(value, gui.KeySequence) else gui.KeySequence(value)
        if seq.count() == 0:
            self.clear()
        else:
            self.setKeySequence(gui.KeySequence(seq[0]))

    def get_value(self) -> str:
        seq = gui.KeySequence(self.keySequence())
        return gui.KeySequence(seq[0]).toString() if seq.count() > 0 else ""

    def is_valid(self) -> bool:
        return True

:fa-brands-github: Show source on GitHub